<?php
/**
 * +-------------------------------------------------------------
 * |Caption:
 * +-------------------------------------------------------------
 * |Author: Lenny
 * +-------------------------------------------------------------
 * |Email:  1685964109@qq.com
 * +-------------------------------------------------------------
 * |Date:   2024/7/27 上午10:27
 * +-------------------------------------------------------------
 */

namespace app\common\controller;

use app\common\enum\Status;
use app\common\model\Company;
use app\common\model\Group;
use think\App;

class AdminController extends CommonController
{
    protected mixed $groupId;
    protected mixed $companyIds;

    /**
     * 应用名
     */
    protected string $appName = 'admin';

    protected array $position;

    /**
     * 初始化方法
     * @return void
     */
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->userInfo   = request()->userInfo ?? [];
        $this->uid        = $this->userInfo['id'] ?? 0;
        $this->groupId    = $this->userInfo['group_id'] ?? 0;
        $this->companyIds = Company::where('status', Status::NORMAL)->where('group_id', $this->groupId)->column('id');
        $this->position   = $this->getGroupPosition();
    }

    private function getGroupPosition(): array
    {
        $info = (new Group())->find($this->groupId);
        return [
                'lng' => $info['lng'] ?? 0,
                'lat' => $info['lat'] ?? 0
        ];
    }
}